﻿/**************************************************************************
 * FileName：CardPostUnit
 * Function：银行卡识别对象
 * Description：
 * Version：
 * ------------------------------------------
 * CreateTime：2024/5/21 10:26
 * Author：金文旭
 * Email： ohayashi@163.com
 * =============================================
 * 
 * Modifyier：	
 * ModifyTime：	
 * Description：	
 ***************************************************************************/
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPractise.CardCheck
{
    /// <summary>
    /// 银行卡识别对象,用于构造Post报文
    /// </summary>
    internal class CardPostUnit
    {
        private string appId;//商户ID
        private string appPwd;//商户密码

        private string cardNo;//银行卡号
        private string customerNm;//用户姓名
        private string phoneNo;//用户手机号
        private string certifId;//用户证件号
        private string certifTp;//用户证件类型
        private string transCode;//交易场景编码

        internal CardPostUnit(string appId, string appPwd, string cardNo, string customerNm, string phoneNo, string certifId, string certifTp, string transCode)
        {
            this.appId = appId;
            this.appPwd = appPwd;
            this.cardNo = cardNo;
            this.customerNm = customerNm;
            this.phoneNo = phoneNo;
            this.certifId = certifId;
            this.certifTp = certifTp;
            this.transCode = transCode;
        }
        /// <summary>
        /// 为了简化结构,将"上送报文"对象拆开存储于CardPostUnit对象中。故需要利用ToString()方法获取Json对象
        /// </summary>
        /// <returns>银行账号验证Json</returns>
        public override string ToString()
        {
            JObject tempJson = new JObject
            {
                { "appId", appId },
                {"appPwd",appPwd}
            };
            //构造上送报文
            string tradeType = default_tradeType;
            Random random = new Random();
            int randint = random.Next(1000, 9999);
            DateTime dateTime = DateTime.Now;
            string orderId = $"{dateTime.Year}{dateTime.Month}{dateTime.Day}{dateTime.Hour}{dateTime.Minute}{dateTime.Second}{randint}";
            JObject data = new JObject
            {
                {"tradeType",tradeType },
                {"cardNo",cardNo },
                {"customerNm",customerNm},
                {"phoneNo",phoneNo},
                {"certifId",certifId},
                {"certifTp",certifTp },
                {"orderId",orderId},
                {"transCode",transCode}
            };
            tempJson.Add(data);
            return tempJson.ToString();
        }

        internal const string default_certifTp = "01";//证件类型:身份证
        internal const string default_transCode = "02";//交易场景编码:商户付款
        private const string default_tradeType = "0401";//查询码:4要素
    }
}
